package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.exception.BaseException;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> setmealPageQuery(SetmealPageQueryDTO dto) {
        PageResult page = setmealService.setmealPageQuery(dto);

        return Result.success(page);
    }

    @PostMapping
    @ApiOperation("新增套餐")
    @CacheEvict(cacheNames = "setmeal",allEntries = true)
    public Result saveSetmeal(@RequestBody SetmealDTO dto) {
        setmealService.saveSetmeal(dto);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("批量删除套餐")
    @CacheEvict(cacheNames = "setmeal",allEntries = true)
    public Result deleteSetmeal(@RequestParam List<Long> ids) {
        setmealService.deleteSetmeal(ids);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改套餐")
    @CacheEvict(cacheNames = "setmeal",allEntries = true)
    public Result updataSetmeal(@RequestBody SetmealDTO dto) {
        setmealService.updataSetmeal(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public Result<SetmealVO> getByid(@PathVariable Long id) {
        SetmealVO setmeal = setmealService.getByid(id);
        return Result.success(setmeal);
    }
    @PostMapping("/status/{status}")
    @ApiOperation("起售停售")
    @CacheEvict(cacheNames = "setmeal",allEntries = true)
    public Result status(@PathVariable Integer status,Long id){
        setmealService.status(status,id);
        return Result.success();
}


}
